package com.dididoctor.patient.Activity.Usercentre.Evaluate;

import android.content.Context;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.Bean.Token;
import com.dididoctor.patient.Http.MyHttpResponseHandler;
import com.dididoctor.patient.MV.BasePresenter;
import com.dididoctor.patient.MV.BusinessClient;
import com.dididoctor.patient.MV.Response;
import com.dididoctor.patient.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/4/8.
 */
public class UserEvaluatePresenter extends BasePresenter {


    private UserEvaluateView view;

    public UserEvaluatePresenter(Context context, UserEvaluateView view) {
        super(context, view);
        this.view = view;
    }

    public void getEvaluate(int pageIndex) {
        RequestParams params = new RequestParams();
//        userId	String	是	用户
//        token	String	是
//        pageIndex	String	String	页码，第一页从开始
//        pageSize	String	String	页容量
        params.put("userId", Token.getId());
        params.put("pageIndex", Util.toString(pageIndex));
        params.put("pageSize", "10");
        params.put("token", Token.getToken());
        BusinessClient.post(ConstantValue.impresslist, params, new MyHttpResponseHandler() {
            private List<UserEvaluate> Evaluates = new ArrayList<UserEvaluate>();
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getListData("impresslist");
                    for (Map<String, String> map : maps) {
                        UserEvaluate evaluate = new UserEvaluate();
//                        "createTime": 1462344308000,
//                                "point": 5,
//                                "imId": 1,
//                                "diseName": "感冒",
//                                "picUrl": "http://app2.doudoutech.com/upload/doctorHeadPic/307/1462441537161ahb_20160503_163053.jpg",
//                                "remark": "hhh",
//                                "name": "张强医生",
//                                "hospital": "中国北京市昌平区生命园西环路"
                        evaluate.setName(map.get("name") + "");
                        evaluate.setImId(Util.toString(map.get("imId")));
                        evaluate.setPicUrl(map.get("picUrl") + "");
                        evaluate.setHospital(map.get("hospital") + "");
                        evaluate.setDiseName(map.get("diseName") + "");
                        evaluate.setRemark(map.get("remark") + "");
                        evaluate.setCreateTime(Util.toString(map.get("createTime")));
                        evaluate.setPoint(Util.toString(map.get("point")));
                        Evaluates.add(evaluate);
                    }
                    view.getEvaluate(Evaluates);
                } else {
                    view.getEvaluate(Evaluates);
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getEvaluatefail();
            }
        });
    }
}
